import { asyncRouter, constantRoutes } from '@/router'

const state = {
  router: []
}

const mutations = {
  setRouter(state, router) {
    state.router = [
      ...constantRoutes,
      ...router
    ]
    // console.log('state.router', state.router)
  }
}

const actions = {
  filterRouter(store, menus) {
    console.log('asyncRouter', asyncRouter)
    const router = asyncRouter.filter(item => {
      return menus.includes(item.name)
    })
    store.commit('setRouter', router)
    console.log('过滤后的路由', router)
    return router
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
